package br.gov.mj.provaconceito.gerencial.servlet;

import java.io.IOException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.mj.provaconceito.Home;
import br.gov.mj.model.TesteEjbRemote;

/**
 * Servlet implementation class Inicio
 */
@WebServlet("/inicio")
public class Inicio extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Inicio() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			Properties env = new Properties();
			env.put(javax.naming.InitialContext.INITIAL_CONTEXT_FACTORY,
					"org.jnp.interfaces.NamingContextFactory");
			env.put(javax.naming.InitialContext.URL_PKG_PREFIXES,
					"org.jboss.naming:org.jnp.interfaces");
			env.put(javax.naming.InitialContext.PROVIDER_URL,
					"jnp://localhost:1199");
			br.com.mj.provaconceito.HomeHome home = br.com.mj.provaconceito.HomeUtil
					.getHome(env);
			Home hello = home.create();
			System.out.println(hello.sayHello("Diego"));

	/*		Properties env2 = new Properties();
			env2.put(Context.INITIAL_CONTEXT_FACTORY,
					"org.jboss.as.naming.InitialContextFactory");
			env2.put(Context.URL_PKG_PREFIXES,
					"org.jboss.naming:org.jnp.interfaces");
			env2.put(Context.PROVIDER_URL, "jnp://localhost:1099");

			InitialContext ctx = new InitialContext(env2);
			TesteEjbRemote testeEjb = (TesteEjbRemote) ctx
					.lookup("java:global/provaconceito-mj-gerencial-ear/provaconceito-mj-gerencial-ejb-1.0-SNAPSHOT/TesteEjb!br.gov.mj.model.TesteEjbRemote");
			System.out.println(testeEjb.digaAlo("Diego"));*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	}

}
